import Mock from 'mockjs'
const Random = Mock.Random

// 生成教师信息
const generateTeacher = () => ({
  id: Random.id(),
  name: Random.cname(),
  title: Random.pick(['教授', '副教授', '讲师', '助教']),
  department: Random.pick(['计算机学院', '数学学院', '物理学院', '化学学院', '文学院'])
})

// 生成课程信息
const generateCourse = () => ({
  id: Random.id(),
  name: Random.pick(['高等数学', '线性代数', '概率论', '数据结构', '算法设计', '计算机网络', '操作系统', '数据库原理']),
  code: `CS${Random.string('number', 4)}`,
  teacher: generateTeacher(),
  schedule: `${Random.pick(['周一', '周二', '周三', '周四', '周五'])} ${Random.pick(['1-2节', '3-4节', '5-6节', '7-8节'])}`,
  location: `${Random.pick(['教学楼A', '教学楼B', '教学楼C'])}${Random.string('number', 3)}`,
  credits: Random.pick([2, 3, 4, 5]),
  status: Random.pick(['ACTIVE', 'COMPLETED', 'DROPPED']),
  weeklyHomeworkCount: Random.integer(0, 5)
})

// 生成通知信息
const generateNotification = () => ({
  id: Random.id(),
  title: Random.ctitle(5, 15),
  message: Random.cparagraph(1, 3),
  type: Random.pick(['SYSTEM', 'COURSE', 'GRADE', 'HOMEWORK']),
  isRead: Random.boolean(),
  createTime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
  sender: {
    id: Random.id(),
    name: Random.pick(['系统管理员', '张老师', '李老师', '王老师', '教务处']),
    type: Random.pick(['SYSTEM', 'TEACHER', 'ADMIN'])
  }
})

// 生成科目成绩
const generateSubjectScore = () => ({
  subjectName: Random.pick(['高等数学', '线性代数', '概率论', '数据结构', '算法设计', '计算机网络', '操作系统', '数据库原理']),
  score: Random.float(60, 100, 1, 1),
  rank: Random.integer(1, 50)
})

// 获取学生仪表板概览
Mock.mock('/api/student/dashboard/overview', 'get', () => {
  return {
    code: 200,
    message: '操作成功',
    data: {
      courseCount: Random.integer(4, 8),
      weeklyHomeworkCount: Random.integer(2, 6),
      averageScore: Random.float(75, 95, 1, 1),
      rank: Random.integer(1, 50),
      totalStudents: Random.integer(40, 60),
      unreadNotificationCount: Random.integer(0, 10),
      totalNotificationCount: Random.integer(10, 30)
    }
  }
})

// 获取学生课程信息
Mock.mock(/\/api\/student\/course(\?.*)?$/, 'get', () => {
  const courses = Array.from({ length: Random.integer(5, 10) }, () => generateCourse())
  
  return {
    code: 200,
    message: '操作成功',
    data: {
      records: courses,
      total: courses.length,
      size: 10,
      current: 1,
      pages: Math.ceil(courses.length / 10)
    }
  }
})

// 获取学生成绩概览
Mock.mock('/api/student/grade/overview', 'get', () => {
  const subjectScores = Array.from({ length: Random.integer(6, 10) }, () => generateSubjectScore())
  const averageScore = subjectScores.reduce((sum, subject) => sum + subject.score, 0) / subjectScores.length
  
  return {
    code: 200,
    message: '操作成功',
    data: {
      averageScore: parseFloat(averageScore.toFixed(1)),
      rank: Random.integer(1, 50),
      totalStudents: Random.integer(40, 60),
      highestScore: Random.float(95, 100, 1, 1),
      lowestScore: Random.float(60, 75, 1, 1),
      passRate: Random.float(85, 98, 1, 1),
      excellentRate: Random.float(20, 40, 1, 1),
      subjectScores: subjectScores
    }
  }
})

// 获取学生通知列表
Mock.mock(/\/api\/student\/notification(\?.*)?$/, 'get', () => {
  const notifications = Array.from({ length: Random.integer(15, 25) }, () => generateNotification())
  
  return {
    code: 200,
    message: '操作成功',
    data: {
      records: notifications,
      total: notifications.length,
      size: 10,
      current: 1,
      pages: Math.ceil(notifications.length / 10)
    }
  }
})

// 标记通知为已读
Mock.mock(/\/api\/student\/notification\/[^/]+\/read/, 'post', () => {
  return {
    code: 200,
    message: '操作成功'
  }
})

// 批量标记通知为已读
Mock.mock('/api/student/notification/read', 'post', () => {
  return {
    code: 200,
    message: '操作成功',
    data: {
      successCount: Random.integer(1, 10),
      failCount: 0
    }
  }
}) 